﻿// NFakeMail - A fake SMTP Server for software testing.
// 
// Copyright (C) 2010, João Angelo
// 
// This file is part of NFakeMail.
//
// NFakeMail is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// NFakeMail is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with NFakeMail; if not, see <http://www.gnu.org/licenses/>.

namespace NFakeMail
{
    using System;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Represents an output data repository that writes the received data to the console.
    /// </summary>
    /// <author> jmangelo </author>
    /// <history>
    /// ______________________________________________________________________________________
    /// History :
    /// 20100816 [+] jmangelo     Initial version
    /// ______________________________________________________________________________________
    /// </history>
    public sealed class ConsoleOutputSink : OutputSink
    {
        public override void Write(string text)
        {
            Console.WriteLine(text);
        }

        public override void Write(FakeMailMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            var output = new StringBuilder();

            output.AppendLine("######### MESSAGE RECEIVED #########");
            output.AppendLine();

            output.AppendFormat("Client: {0}:{1}", message.Client.Address, message.Client.Port);
            output.AppendLine();
            output.AppendFormat("From: {0}", message.From.Address);
            output.AppendLine();
            output.AppendFormat("Recipients: {0}", String.Join(", ", message.Recipients.Select(a => a.Address)));
            output.AppendLine();
            output.AppendFormat("Subject: {0}", message.Subject);
            output.AppendLine();

            output.AppendLine();
            output.AppendLine("####################################");

            Console.Write(output);
        }
    }
}
